package com.ylkj.patient.moduleimpl;

import android.app.Activity;
import android.content.Context;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.baidu.mobstat.StatService;
import com.users.rn.common.cmbroadcast.RNKITTools;
import com.users.rn.rncommon.ARouterCommonConstants;
import com.users.rn.rncommon.ActivityType;
import com.users.rn.rncommon.CommonApi;
import com.yilijk.base.utils.ALog;
import com.yilijk.base.utils.ActivityManagerUtils;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by SHICHENG
 * <p>
 * Time on 2021/12/28
 */
@Route(path = ARouterCommonConstants.RNBaiduBackImpl)
public class CommonImpl implements CommonApi {
//    @Override
//    public void onResume(Activity activity) {
//
//    }
//
//    @Override
//    public void onPause(Activity activity) {
//
//    }
//
//    @Override
//    public void onPageStart(Activity activity, String s) {
//
//    }
//
//    @Override
//    public void onPageEnd(Activity activity,String s) {
//
//    }
//
//    @Override
//    public void onEvent(Activity activity) {
//        StatService.onEvent(activity,"","");
//    }
//    @Override
//    public void onEventStart(Activity activity) {
//        StatService.onEventStart(activity,"","");
//    }
//    @Override
//    public void onEventEnd(Activity activity) {
//        StatService.onEventEnd(activity,"","");
//    }
//    @Override
//    public void addActivities(Activity activity) {
//
//    }
//
//    @Override
//    public void removeActivities(Activity activity) {
//
//    }

    @Override
    public void onActivityLifecycle(ActivityType activityType, Activity activity, String s) {
        switch (activityType) {
            case ACTIVITY_CREATE:
                ActivityManagerUtils.addActivities(activity);
                break;
            case ACTIVITY_START:
                StatService.onPageStart(activity, s);
                ALog.i("百度统计onPageStart", s);
                break;
            case ACTIVITY_RESUME: {
                StatService.onResume(activity);
                ALog.i("百度统计onResume", activity.getClass().toString());
                JSONObject jsonObject = new JSONObject();
                try {
                    jsonObject.put("tag", "onPageResume");
                    jsonObject.put("pageName", s);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                RNKITTools.INSTANCE.sendBroadcast(activity, "onPageResume", jsonObject.toString());

                break;
            }
            case ACTIVITY_PAUSE: {
                StatService.onPause(activity);
                ALog.i("百度统计onPause", activity.getClass().toString());
                JSONObject jsonObject = new JSONObject();
                try {
                    jsonObject.put("tag", "onPagePause");
                    jsonObject.put("pageName", s);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                RNKITTools.INSTANCE.sendBroadcast(activity, "onPagePause", jsonObject.toString());

                break;
            }
            case ACTIVITY_STOP:

                break;
            case ACTIVITY_RESTART:

                break;
            case ACTIVITY_DESTORY:
                StatService.onPageEnd(activity, s);
                ALog.i("百度统计onPageEnd", s);
                ActivityManagerUtils.removeActivities(activity);
                break;
        }
    }

    @Override
    public String[] onPageGroup() {
        return new String[]{
                "AddHealthSurgery",
                "HelpAndBackPage",
                "EpidemicControlInformation",
                "MyOrder",
                "MyMedicaltransfer",
                "MedicaltransferDetail",
                "ReferralApplication",
        };
    }

    @Override
    public void init(Context context) {

    }

    @Override
    public String[] onForbiddenBack() {
        return new String[]{
                "Index",
        };
    }
}
